#include "itools.h"

void setIntField(JNIEnv *env, jobject obj, const char* name, jint value) {
	jclass cls = (*env)->GetObjectClass(env, obj);
	jfieldID fieldId = (*env)->GetFieldID(env, cls, name,
			"I");
	(*env)->SetIntField(env, obj, fieldId, value);
}

void setStaticIntField(JNIEnv *env, jclass cls, const char* name, jint value) {
	jfieldID fieldId = (*env)->GetStaticFieldID(env, cls, name,
			"Ljava/lang/Integer;");
	(*env)->SetStaticIntField(env, cls, fieldId, value);
}

jint getIntField(JNIEnv *env, jobject obj, const char* name) {
	jclass cls = (*env)->GetObjectClass(env, obj);
	jfieldID fieldId = (*env)->GetFieldID(env, cls, name,
			"I");
	(*env)->GetIntField(env, obj, fieldId);
}

jint getStaticIntField(JNIEnv *env, jclass cls, const char* name) {
	jfieldID fieldId = (*env)->GetStaticFieldID(env, cls, name,
			"Ljava/lang/Integer;");
	(*env)->GetStaticIntField(env, cls, fieldId);
}

void setObjectField(JNIEnv *env, jobject obj, const char* name,
		const char* clsName, jobject value) {
	jclass cls = (*env)->GetObjectClass(env, obj);
	jfieldID fieldId = (*env)->GetFieldID(env, cls, name, clsName);
	(*env)->SetObjectField(env, obj, fieldId, value);
}

void setStaticObjectField(JNIEnv *env, jclass cls, const char* name, const char* clsName, jobject value){
	jfieldID fieldId = (*env)->GetStaticFieldID(env, cls, name, clsName);
	(*env)->SetStaticObjectField(env, cls, fieldId, value);
}
